home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / monax25 / circuit.c < prev    next >
Text File  |  1987-10-18  |  4KB  |  187 lines

  1. /* circuit.c - Report on number of circuits per interval.
  2.    This module is part of report.exe
  3.                   
  4.    Language = Microsoft C version 4.0
  5.  
  6.  
  7.    This source is distributed freely and may be copied and
  8.    redistributed with the following provisos:
  9.    
  10.            You may not sell it, nor may you charge for making 
  11.            copies beyond the actual cost of mailing and media.
  12.                       
  13.    Written by Skip Hansen WB6YMH and Harold Price NK6K.
  14.  
  15.    Feedback is desired.
  16.  
  17.    RCP/M (213) 541-2503 300/1200/2400 baud
  18.    or via packet WB6YMH @ WB6YMH-2 or 
  19.          NK6K @ NK6K
  20.  
  21.    Modification history:
  22.  
  23.     8/10/87         NK6K: Initial release.    
  24.     ver 1.0         
  25.  
  26.    10/18/87     NK6K: First general release.
  27.    ver 1.1
  28. */
  29. /* circuit - report on number of circuits per interval */
  30. #define LINT_ARGS
  31. #include "monfile.h"
  32. #include <stdio.h>
  33. #include <memory.h>
  34. static struct CIRCUIT_RECORD ccrec;
  35. static struct FREQ_RECORD cfrec;
  36.  
  37. extern FILE *fin,*fout;
  38. extern char *getrec();
  39.  
  40. static long total_packets;
  41. static long total_retries;
  42. static long total_poll;
  43. static long total_final;
  44. static long total_rej;
  45. static long total_rnr;
  46. static long total_bytes;
  47. static long total_ubytes;
  48.  
  49. static char fbuf[257];
  50. static char started;
  51. static unsigned long time_stamp;
  52. static unsigned int all_cir,user_cir;
  53. static int tmp;
  54. static long recnum;
  55.  
  56.  
  57. report_circuit()
  58. {
  59.    started=0;
  60.    recnum=0;
  61.    total_bytes=total_ubytes=total_rej=total_rnr=total_poll=
  62.        total_final=total_packets=total_retries=all_cir=user_cir=0;
  63.    while (1){
  64.     if (getrec(fbuf,256,fin)==NULL) {
  65.         if (started) cdump_it();
  66.         return;
  67.         }
  68.     recnum++;
  69.     if (fbuf[0]=='T') {
  70.         if (started) cdump_it();
  71.         tmp=sscanf(fbuf+2,"%lu",&time_stamp);    
  72.         if (tmp!=1) {
  73.             cprintf("*** bad Time rec, number %lu ***\r\n",recnum);
  74.             }
  75.         started=1;
  76.         }
  77.  
  78.     else if (fbuf[0]== FREQ_TYPE) {
  79.         tmp=sscanf(fbuf+2,"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu",
  80.             &cfrec.t_packets,
  81.             &cfrec.t_bytes,
  82.             &cfrec.u_packets,
  83.             &cfrec.u_bytes,
  84.             &cfrec.l32,
  85.             &cfrec.l64,
  86.             &cfrec.l128,
  87.             &cfrec.l256,
  88.             &cfrec.g256,
  89.             &cfrec.dcd_on_ticks,
  90.             &cfrec.dcd_off_ticks);
  91.  
  92.         if (tmp!=11) {
  93.             cprintf("*** bad Freq rec, number %lu ***\r\n",recnum); 
  94.             continue;
  95.             }
  96.         }
  97.         
  98.     else if (fbuf[0]=='C') {
  99.         all_cir++;
  100.         tmp = sscanf(fbuf+2,
  101. "%[^,],%[^,],%u,%u,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,\
  102. %lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu",
  103.         ccrec.to,        
  104.         ccrec.from,        
  105.         &ccrec.digis,        
  106.         &ccrec.pid,
  107.         &ccrec.u_dpackets,    
  108.         &ccrec.nd_dpackets,    
  109.         &ccrec.t_dpackets,    
  110.         &ccrec.nd_packets,    
  111.         &ccrec.t_packets,    
  112.         &ccrec.u_dbytes,        
  113.         &ccrec.nd_dbytes,    
  114.         &ccrec.t_dbytes,        
  115.         &ccrec.nd_bytes,        
  116.         &ccrec.t_bytes,        
  117.         &ccrec.c_time,        
  118.         &ccrec.sabm,
  119.         &ccrec.ua,
  120.         &ccrec.disc,
  121.         &ccrec.dm,
  122.         &ccrec.rej,
  123.         &ccrec.rr,
  124.         &ccrec.rnr,
  125.         &ccrec.i,
  126.         &ccrec.ui,
  127.         &ccrec.frmr,
  128.         &ccrec.poll,
  129.         &ccrec.final,
  130.         &ccrec.l32,    
  131.         &ccrec.l64,    
  132.         &ccrec.l128,
  133.         &ccrec.l256,
  134.         &ccrec.g256);
  135.  
  136.         if (tmp!=32) {
  137.             cprintf("*** bad Circuit rec, number %lu ***\r\n",recnum); 
  138.             continue;
  139.             }
  140.  
  141.         
  142.             /* if only UI frames are sent, and if the
  143.                total number is less than 1 per minute, this
  144.                is probably a beacon.  Ignore it. */
  145.         if ((ccrec.t_packets > ccrec.ui) || (ccrec.ui>5))  user_cir++;
  146.  
  147. /*n* fix this later */
  148.         if ((ccrec.nd_dpackets-ccrec.u_dpackets) >= 0) {
  149.             total_packets += ccrec.t_packets;
  150.             total_retries += ccrec.nd_dpackets-ccrec.u_dpackets;
  151.             total_poll += ccrec.poll;
  152.             total_final += ccrec.final;
  153.             total_rnr += ccrec.rnr;
  154.             total_rej += ccrec.rej;
  155.             total_bytes += ccrec.t_bytes;
  156.             total_ubytes += ccrec.u_dbytes;
  157.              }
  158.         }
  159.  
  160.     }
  161.    }
  162.  
  163.         
  164.  
  165.  
  166. cdump_it()
  167. {
  168. long tmpi;
  169.     fprintf(fout,"%lu,%u,%u,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%u\n",
  170.         time_stamp,all_cir,user_cir,total_packets,total_retries,
  171.         total_poll, total_final, total_rej, total_rnr, total_bytes,
  172.         total_ubytes,
  173.         (int) (0.5+ (100.0 * ((float) cfrec.dcd_on_ticks /    
  174.           (float) (cfrec.dcd_on_ticks+cfrec.dcd_off_ticks))))  );
  175.  
  176.  
  177.     if (total_packets != cfrec.t_packets)
  178.         cprintf("Mismatch in packet counts near record %u, computed=%u, f=%u\r\n",
  179.             recnum,total_packets,cfrec.t_packets);
  180.  
  181.     total_bytes=total_ubytes=total_rej=total_rnr=total_poll=
  182.                total_final=total_packets=total_retries=all_cir=user_cir=0;
  183.  
  184.  
  185.     }
  186.  
  187.